{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Find the Width of Columns of a Grid"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #矩阵"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: findColumnWidth"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #查询网格图中每一列的宽度"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个下标从 <strong>0</strong>&nbsp;开始的&nbsp;<code>m x n</code>&nbsp;整数矩阵&nbsp;<code>grid</code>&nbsp;。矩阵中某一列的宽度是这一列数字的最大 <strong>字符串长度</strong>&nbsp;。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>比方说，如果&nbsp;<code>grid = [[-10], [3], [12]]</code>&nbsp;，那么唯一一列的宽度是&nbsp;<code>3</code>&nbsp;，因为&nbsp;<code>-10</code>&nbsp;的字符串长度为&nbsp;<code>3</code>&nbsp;。</li>\n",
    "</ul>\n",
    "\n",
    "<p>请你返回一个大小为 <code>n</code>&nbsp;的整数数组&nbsp;<code>ans</code>&nbsp;，其中&nbsp;<code>ans[i]</code>&nbsp;是第&nbsp;<code>i</code>&nbsp;列的宽度。</p>\n",
    "\n",
    "<p>一个有 <code>len</code>&nbsp;个数位的整数 <code>x</code>&nbsp;，如果是非负数，那么&nbsp;<strong>字符串</strong><strong>长度</strong>&nbsp;为&nbsp;<code>len</code>&nbsp;，否则为&nbsp;<code>len + 1</code>&nbsp;。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>grid = [[1],[22],[333]]\n",
    "<b>输出：</b>[3]\n",
    "<b>解释：</b>第 0 列中，333 字符串长度为 3 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>grid = [[-15,1,3],[15,7,12],[5,6,-2]]\n",
    "<b>输出：</b>[3,1,2]\n",
    "<b>解释：</b>\n",
    "第 0 列中，只有 -15 字符串长度为 3 。\n",
    "第 1 列中，所有整数的字符串长度都是 1 。\n",
    "第 2 列中，12 和 -2 的字符串长度都为 2 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>m == grid.length</code></li>\n",
    "\t<li><code>n == grid[i].length</code></li>\n",
    "\t<li><code>1 &lt;= m, n &lt;= 100 </code></li>\n",
    "\t<li><code>-10<sup>9</sup> &lt;= grid[r][c] &lt;= 10<sup>9</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [find-the-width-of-columns-of-a-grid](https://leetcode.cn/problems/find-the-width-of-columns-of-a-grid/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [find-the-width-of-columns-of-a-grid](https://leetcode.cn/problems/find-the-width-of-columns-of-a-grid/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[[1],[22],[333]]', '[[-15,1,3],[15,7,12],[5,6,-2]]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(x)) for x in col) for col in zip(*grid)]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(x)) for x in col) for col in zip(*grid)]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = []\n",
    "        r,c = len(grid),len(grid[0])\n",
    "        for i in range(c):\n",
    "            t = 0\n",
    "            for j in range(r):\n",
    "                t = max(t,len(str(grid[j][i])))\n",
    "            ans.append(t)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        s = []\n",
    "        for j in range(len(grid[0])):\n",
    "            s.append(max(len(str(grid[i][j])) for i in range(len(grid))))\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(i)) for i in col) for col in zip(*grid)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        x = zip(*grid)\n",
    "        res = []\n",
    "        for i in x:\n",
    "            res.append(max(len(str(j)) for j in i))\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "\n",
    "        ans = []\n",
    "        for l,i in enumerate(grid):\n",
    "            for k,j in enumerate(i):\n",
    "                if l==0:\n",
    "                    ans.append(len(str(j)))\n",
    "                else:\n",
    "                    if len(str(j)) > ans[k]:\n",
    "                        ans[k] = len(str(j))\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        B=grid.copy()\n",
    "        for i in range(len(grid)):\n",
    "            for j in range(len(grid[0])):\n",
    "                B[i][j]=len(str(grid[i][j]))\n",
    "        A=list(zip(*B))\n",
    "        res=[]\n",
    "        for i in range(len(A)):\n",
    "            res+=[max(A[i])]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(len(grid[0])):\n",
    "            ans.append(max(len(str(grid[j][i])) for j in range(len(grid))))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = [0] * len(grid[0])\n",
    "        for i in range(len(grid)):\n",
    "            for j in range(len(grid[0])):\n",
    "                temp_len = len(str(grid[i][j]))\n",
    "                if temp_len > ans[j]:\n",
    "                    ans[j] = temp_len\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(map(len, map(str, l))) for l in zip(*grid)]\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        n,m=len(grid),len(grid[0])\n",
    "        ans=[]\n",
    "        for x in range(m):\n",
    "            length=max(len(str(grid[y][x])) for y in range(n))\n",
    "            ans.append(length)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(x)) for x in col) for col in zip(*grid)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        m, n=len(grid), len(grid[0])\n",
    "        ret=[]\n",
    "        for i in range(n):\n",
    "            mx=0\n",
    "            for j in range(m):\n",
    "                mx=max(mx,len(str(grid[j][i])))\n",
    "            ret.append(mx)\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(i)) for i in l) for l in zip(*grid)]\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        def countDigits(num: int) -> int:\n",
    "            ans = 0\n",
    "            while num:\n",
    "                num //= 10\n",
    "                ans += 1\n",
    "            return ans\n",
    "        res = []\n",
    "        l = len(grid)\n",
    "        ll = len(grid[0])\n",
    "        for i in range(ll):\n",
    "            the_max = 1\n",
    "            for j in range(l):\n",
    "                if grid[j][i] >= 0:\n",
    "                    the_max = max(the_max, countDigits(grid[j][i]))\n",
    "                else:\n",
    "                    the_max = max(the_max, countDigits(-grid[j][i]) + 1)\n",
    "            res.append(the_max)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        \n",
    "        N = len(grid[0])\n",
    "        res = [0] * N\n",
    "        for row in grid:\n",
    "            for i, n in enumerate(row):\n",
    "                res[i] = max(res[i], len(str(n)))\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        w=len(grid[0])\n",
    "        st=[0]*w\n",
    "        for line in grid:\n",
    "            for i in range(w):\n",
    "                st[i]=max(st[i],len(str(line[i])))\n",
    "        return st"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(x)) for x in col) for col in zip(*grid)]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        def getexp(val):\n",
    "            if val == 0:\n",
    "                return 1\n",
    "            exp = 0\n",
    "            while val > 0:\n",
    "                exp += 1\n",
    "                val //= 10\n",
    "            return exp\n",
    "\n",
    "        rows, cols = grid.__len__(), grid[0].__len__()\n",
    "        ans = []\n",
    "        for j in range(cols):\n",
    "            maximum = 0\n",
    "            for i in range(rows):\n",
    "                val = grid[i][j]\n",
    "                l = 0\n",
    "                if val < 0:\n",
    "                    l += 1\n",
    "                    val = -val\n",
    "                maximum = max(maximum, getexp(val)+l)\n",
    "            ans.append(maximum)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(j)) for j in i) for i in zip(*grid)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max((len(str(n)) for n in row)) for row in zip(*grid)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = []\n",
    "        for row in zip(*grid):\n",
    "            s = 0\n",
    "            for n in row:\n",
    "                s = max(s, len(str(n)))\n",
    "            ans.append(s)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        m, n = len(grid), len(grid[0])\n",
    "        ans = [0] * n\n",
    "        for i, row in enumerate(grid):\n",
    "            for j, x in enumerate(row):\n",
    "                ans[j] = max(ans[j], len(str(x)))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        m = len(grid)\n",
    "        n = len(grid[0])\n",
    "        res = [0]*n\n",
    "        for item in grid:\n",
    "            for i in range(n):\n",
    "                res[i] = max(res[i], len(str(item[i])))\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        s=list(zip(*grid))\n",
    "        x=[]\n",
    "        for i in range(len(s)):\n",
    "            c=0\n",
    "            for j in range(len(s[0])):\n",
    "                c=max(c,len(str(s[i][j])))\n",
    "            x.append(c)\n",
    "        return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = []\n",
    "        r,c = len(grid),len(grid[0])\n",
    "        for i in range(c):\n",
    "            t = 0\n",
    "            for j in range(r):\n",
    "                t = max(t,len(str(grid[j][i])))\n",
    "            ans.append(t)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        n = len(grid[0])\n",
    "        res = [0] * n\n",
    "        for row in grid:\n",
    "            for i in range(n):\n",
    "                if (l := len(str(row[i]))) > res[i]:\n",
    "                    res[i] = l\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(grid[i][j])) for i in range(len(grid))) for j in range(len(grid[0]))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [*(max(len(str(x)) for x in c) for c in zip(*grid))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(x)) for x in col) for col in zip(*grid)]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = []\n",
    "        for j in range(len(grid[0])):\n",
    "            count = 0\n",
    "            for i in range(len(grid)):\n",
    "                count = max(count,len(str(grid[i][j])))\n",
    "            ans.append(count)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(x)) for x in col) for col in zip(*grid)]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = []\n",
    "        for l,i in enumerate(grid):\n",
    "            for k,j in enumerate(i):\n",
    "                if l==0:\n",
    "                    ans.append(len(str(j)))\n",
    "                else:\n",
    "                    if len(str(j)) > ans[k]:\n",
    "                        ans[k] = len(str(j))\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        cols = len(grid[0])\n",
    "        res = [0]*cols\n",
    "        for col in range(cols):\n",
    "            res[col] = max(len(str(row[col])) for row in grid)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(len(grid[0])):\n",
    "            tmp = 0\n",
    "            for j in range(len(grid)):\n",
    "                tmp = max(tmp, len(str(grid[j][i])))\n",
    "            ans.append(tmp)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "            \n",
    "        rows, cols = len(grid), len(grid[0])\n",
    "        ans = [1] * cols\n",
    "        for j in range(cols):\n",
    "            for i in range(rows):\n",
    "                ans[j] = max(ans[j], len(str(grid[i][j])))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        rows = len(grid)\n",
    "        cols = len(grid[0])\n",
    "        res = []\n",
    "        maxl = -1\n",
    "        for j in range(cols):\n",
    "            maxl = -1\n",
    "            for i in range(rows):\n",
    "                maxl = max(maxl,len(str(grid[i][j])))\n",
    "            res.append(maxl)\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        m = len(grid)\n",
    "        n = len(grid[0])\n",
    "        ans = [0] * n\n",
    "        for i in range(n):\n",
    "            col = [r[i] for r in grid]\n",
    "            ans[i] = max(len(str(max(col))), len(str(min(col))))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\r\n",
    "        m, n, ans = len(grid), len(grid[0]), []\r\n",
    "        for j in range(n):\r\n",
    "            nums = [len(str(grid[i][j])) for i in range(m)]\r\n",
    "            ans.append(max(nums))\r\n",
    "\r\n",
    "        return ans\r\n",
    "\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        h, w = len(grid), len(grid[0])\n",
    "        rv = [0] * w \n",
    "        for line in grid:\n",
    "            for i in range(w):\n",
    "                x = line[i]\n",
    "                ss = str(x)\n",
    "                v = len(ss)\n",
    "                rv[i] = max(rv[i], v)\n",
    "        return rv "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def get_length(self, num):\n",
    "        if num == 0:\n",
    "            return 1\n",
    "        elif num < 0:\n",
    "            return 1 + self.get_length(-num)\n",
    "        else:\n",
    "            res = 0\n",
    "            while num > 0:\n",
    "                res += 1\n",
    "                num //= 10\n",
    "            \n",
    "            return res\n",
    "        \n",
    "        \n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        m, n = len(grid), len(grid[0])\n",
    "        res = []\n",
    "        for i in range(n):\n",
    "            res.append(0)\n",
    "            for j in range(m):\n",
    "                tmp = self.get_length(grid[j][i])\n",
    "                if tmp > res[-1]:\n",
    "                    res[-1] = tmp\n",
    "        \n",
    "        return res\n",
    "                    \n",
    "                    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        def length(num):\n",
    "            if num > 0:\n",
    "                l = 0\n",
    "            else:\n",
    "                num = -num\n",
    "                l = 1\n",
    "            while num > 0:\n",
    "                num = num // 10\n",
    "                l += 1\n",
    "            return l\n",
    "        \n",
    "        res = [0] * len(grid[0])\n",
    "        for x in grid:\n",
    "            for i, y in enumerate(x):\n",
    "                res[i] = max(res[i], length(y))\n",
    "        return res\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = []\n",
    "        for col in range(len(grid[0])):\n",
    "            big, small = -inf, inf\n",
    "            for row in range(len(grid)):\n",
    "                big = max(big, grid[row][col])\n",
    "                small = min(small, grid[row][col])\n",
    "            ans.append(max(len(str(big)), len(str(small))))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\r\n",
    "        rows, cols = len(grid), len(grid[0])\r\n",
    "        res = []\r\n",
    "        for c in range(cols):\r\n",
    "            mx = 0\r\n",
    "            for r in range(rows):\r\n",
    "                mx = max(mx, len(str(grid[r][c])))\r\n",
    "            res.append(mx)\r\n",
    "        return res\r\n",
    "\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        m = len(grid)\n",
    "        n = len(grid[0])\n",
    "        col = [0] * n\n",
    "        for i in range(m):\n",
    "            for j in range(n):\n",
    "                col[j] = max(col[j], len(str(grid[i][j])))\n",
    "        return col"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        def length(num):\n",
    "            if num > 0:\n",
    "                l = 0\n",
    "            else:\n",
    "                num = -num\n",
    "                l = 1\n",
    "            while num > 0:\n",
    "                num = num // 10\n",
    "                l += 1\n",
    "            return l\n",
    "        \n",
    "        res = [0] * len(grid[0])\n",
    "        for x in grid:\n",
    "            for i, y in enumerate(x):\n",
    "                res[i] = max(res[i], len(str(y)))\n",
    "        return res\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:        \n",
    "        res = [0] * len(grid[0])\n",
    "        for x in grid:\n",
    "            for i, y in enumerate(x):\n",
    "                res[i] = max(res[i], len(str(y)))\n",
    "        return res\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(x)) for x in col) for col in zip(*grid)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        return [max(len(str(s)) for s in lst) for lst in zip(*grid)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = []\n",
    "        for l,i in enumerate(grid):\n",
    "            for k,j in enumerate(i):\n",
    "                if l==0:\n",
    "                    ans.append(len(str(j)))\n",
    "                else:\n",
    "                    ans[k] = max(len(str(j)), ans[k])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        m = len(grid[0])\n",
    "        out = [0]*m\n",
    "        for i in range(m):\n",
    "            tem = [len(str(grid[k][i])) for k in range(len(grid))]\n",
    "            out[i] = max(tem)\n",
    "        return out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        n=len(grid[0])\n",
    "        m=len(grid)\n",
    "        ans=[]\n",
    "        nums=0\n",
    "        for i in range(n):\n",
    "            for j in range(m):\n",
    "                if len(str(grid[j][i]))>nums:\n",
    "                    nums=len(str(grid[j][i]))\n",
    "            ans.append(nums)\n",
    "            nums=0\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = [0] * len(grid[0])\n",
    "        for x in grid:\n",
    "            for i in range(len(x)):\n",
    "                ans[i] = max(ans[i],len(str(x[i])))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = []\n",
    "        for l,i in enumerate(grid):\n",
    "            for k,j in enumerate(i):\n",
    "                if l==0:\n",
    "                    ans.append(len(str(j)))\n",
    "                else:\n",
    "                    ans[k] = max(len(str(j)), ans[k])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        array = list(zip(*grid))\n",
    "        ans = []\n",
    "        for row in array:\n",
    "            s = max((len(str(n)) for n in row))\n",
    "            ans.append(s)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        ans = [0] * len(grid[0])\n",
    "        for j, col in enumerate(zip(*grid)):\n",
    "            for x in col:\n",
    "                x_len = int(x <= 0)\n",
    "                x = abs(x)\n",
    "                while x:\n",
    "                    x_len += 1\n",
    "                    x //= 10\n",
    "                ans[j] = max(ans[j], x_len)\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        m, n = len(grid), len(grid[0])\n",
    "        res = [0]*n\n",
    "        for i in grid:\n",
    "            for j in range(n):\n",
    "                res[j] = max(res[j], len(str(i[j])))\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        n = len(grid[0])\n",
    "        res = [0] * n\n",
    "        for j in range(n):\n",
    "            for i in range(len(grid)):\n",
    "                res[j] = max(res[j], len(str(grid[i][j])))\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findColumnWidth(self, grid: List[List[int]]) -> List[int]:\n",
    "        array = list(zip(*grid))\n",
    "        ans = []\n",
    "        for row in array:\n",
    "            s = 0\n",
    "            for n in row:\n",
    "                s = max(s, len(str(n)))\n",
    "            ans.append(s)\n",
    "        return ans"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
